public class Solution1894 {
    public int chalkReplacer(int[] chalk, int k) {
        // 当前学生
        int curStudent = 0;  // 0~n-1
        while (true) {
            if ((k - chalk[curStudent]) < 0) {
                return curStudent;
            }
            else{
                k = k - chalk[curStudent];
                curStudent++;
                if (curStudent >= chalk.length) {
                    curStudent = 0;
                }
            }
        }
    }

    public static void main(String[] args) {
        Solution1894 solution1894=new Solution1894();
        System.out.println(solution1894.chalkReplacer(new int[]{3,4,1,2},25));
    }
}
